﻿using Qy.Common;
using Qy.Models;
using Qy.Repository;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Qy.Service
{
    [AppService]
    public class LogService
    {
        private readonly LogRepository _logRepository;

        public LogService(LogRepository logRepository)
        {
            _logRepository = logRepository;
        }


        /// <summary>
        /// 获取全部列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<Page<ViewLogSql>> GetSqlListAsync(int page, int limit, int uid)
        {
            return await _logRepository.GetSqlListAsync(page, limit, uid, "Id desc");
        }
        /// <summary>
        /// 获取用户ID列表指定条数
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<List<ViewLogSql>> GetListAsync(int uid)
        {
            return await _logRepository.GetListAsync(uid);
        }
        public async Task<object> InsertLogLoginAsync(UserAction user)
        {
            LogSql logSql = new()
            {
                UserId = user.UserId,
                Ip = user.Ip,
                Time = DateTime.Now
            };
            return await _logRepository.InsertAsync(logSql);
        }
        public async Task<int> Clear()
        {
            return await _logRepository.Clear();
        }
    }
}
